/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author serga
 */
@Entity
@Table(name="messages", catalog="", schema="")
@NamedQueries({
    @NamedQuery(name="Messages.sendMessageToUser", query = "SELECT m FROM messages m WHERE m.id = :id_user_to" ),
    @NamedQuery(name="Messages.getNewUserMessage", query = "SELECT m FROM messages m WHERE m.id_user = :id_user_from")
})




public class Messages extends BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    
    
    @Column(name="text")
    private String  text;
    @ManyToOne
    @JoinColumn(name="id", referencedColumnName="id_user_to")
    private Users userTo;
    @ManyToOne
    @JoinColumn(name="id_user", referencedColumnName="id_user_from")
    private Users userFrom;
    
    
    
   /* private String text;
    private Users userFrom;
    private Users userTo;*/
    private boolean isRead;

    public Messages() {
    }
    
    public Messages (Long id) {
        this.id = id;
    }
    
    public Messages (boolean isRead,String text,Users userFrom,Users userTo) {
        this.isRead = isRead;
        this.text = text;
        this.userFrom = userFrom;
        this.userTo = userTo;
    }
    
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Users getUserFrom() {
        return userFrom;
    }

    public void setUserFrom(Users userFrom) {
        this.userFrom = userFrom;
    }
    
    public Users getUserTo() {
        return userTo;
    }

    public void setUserTo(Users userTo) {
        this.userTo = userTo;
    }
    
    public boolean isRead() {
        return isRead;
    }

    public void setMessageRead(boolean isRead) {
        this.isRead = isRead;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Messages)) {
            return false;
        }
        Messages other = (Messages) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "models.Messages[ id=" + id + " ]";
    }
    
}
